<?php

namespace app\share\controller;


use app\common\ResponseFormat;
use app\common\UploadImage;
use think\Controller;

/**
 * Class 文件上传控制器 用于汇总所有上传逻辑
 * @package app\admin\controller
 */
class Upload extends Controller {

    /**
     * 构造函数
     * @access public
     */
    public function __construct(){
        parent::__construct();
    }

    /**
     * @date 2019/7/30 17:07
     * @description 图片上传
     * @author cxh
     */
    public function upload_image(){
        $upload_path = input('param.upload_path');
        if(empty($_FILES)){
            return ResponseFormat::failed_array(ResponseFormat::FAILED,'未上传任何文件');
        }
        $update_image = new UploadImage($upload_path);
        if($upload_result = $update_image->up($_FILES['file'])){
            return ResponseFormat::success_array($upload_result,ResponseFormat::SUCCESS,'上传成功');
        } else {
            return ResponseFormat::failed_array(ResponseFormat::BUSINESS_LOGIC_RESTRICT,$update_image->upload_error());
        }
    }


    /**
     * @date 2019/7/30 17:07
     * @description 多图上传
     * @author cxh
     */
    public function upload_multi_images(){
        $upload_path = input('param.upload_path');
        if(empty($_FILES)){
            return ResponseFormat::failed_array(ResponseFormat::FAILED,'未上传任何文件');
        }
        $update_image = new UploadImage($upload_path);
        if($upload_result = $update_image->multi_up($_FILES['file'])){
            return ResponseFormat::success_array($upload_result,ResponseFormat::SUCCESS,'上传成功');
        } else {
            return ResponseFormat::failed_array(ResponseFormat::BUSINESS_LOGIC_RESTRICT,$update_image->upload_error());
        }
    }





}